// 04myCenter/09inviteBusiness/inviteBusiness.js
var co = require('../../resource/js/common.js')
var _this, _data
var app = getApp()
var _qrParam
Page({

   /**
    * 页面的初始数据
    */
   data: {
      inviteQRCode: '', //二维码图片
      showCode: '', //显示二维码图片
      //   outShow:true,//关闭按钮
   },

   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function(options) {
      _this = this
      _data = this.data
      this.createQRCode()
   },
   //显示二维码
   showCode: function() {
      this.setData({
         showCode: true,
         outShow: false
      })
      this.createQRCode()
   },

   // 创建二维码
   createQRCode() {
      wx.showLoading({
         title: '邀请码生成中…',
      })
      var param = app.Data.app
      console.log('appD', app.Data)
      console.log('param===', param)
      param.scene = "InviterID." + app.Data.userInfo.User_ID

      param.wxapp_page_path = '01wasteRecovery/wasteRecovery'
      var url = "https://h5.jyhs.ls293.cn/" + param.appid + '/' + param.wxapp_page_path + "/" + param.scene + 's.png'
      this.setData({
         inviteQRCode: url
      })
      _qrParam = param
      setTimeout(function() {
         wx.hideLoading()
      }, 350);
   },

   //图片加载错误时回调
   onImgError(e) {
      co.getJyhsApi('api/Weixin/getWxAppCodeUnlimit', _qrParam, function(res) {
         if (res.code == 0) {
            _this.setData({
               inviteQRCode: res.data.wxapp_code_url
            })
            wx.hideLoading()
         }
      })
   },

   //分享
   onShareAppMessage() {
      var urlParam = ''
      if (app.Data.userInfo.User_ID) {
         urlParam = '?scene=InviterID.' + app.Data.userInfo.User_ID
      }
      console.log('【app.Data.userInfo】==', app.Data.userInfo)
      console.log('【urlParam】==', urlParam)
      var timestamp = Date.parse(new Date())

      return {
         title: '【旧约回收】欢迎您一键预约上门服务',
         path: '/01wasteRecovery/wasteRecovery' + urlParam,
         // imageUrl: 'http://h5.52g3.cc/h5/invite/invite_image.png?v=' + timestamp,
         imageUrl: 'http://h5.jyhs.ls293.cn/img/lunbotu01_500x400.png?v=' + timestamp,
         success: function(res) {
            console.log("【分享成功res】===", res)
            var pages = getCurrentPages() //获取加载的页面
            var currentPage = pages[pages.length - 1] //获取当前页面的对象
            app.getShareInfo(res, '邀请商家', currentPage.route)
         }
      }
   },

   onUnload: function() {
      _qrParam = ''
   },
})